﻿
@if (OnlyShowContext)
{
        @ChildContent
}
else
{
    <section id="@SectionId" class="@($"{Class}")">
        <MDCard Outline="OutlineHead" Class="@($"title-container-card h-100 {(IsCollapsed ? " mb-3" : "")}")">
            <div class="@($"title-card {(OutlineHead?"":"pa-3")}") ">
                <h2 class="@($"{ButtonColor}-text title-{(Small?"medium":"large")}")">
                    <MIcon Color="@ButtonColor" Class="me-4" Small="Small">@Icon</MIcon>
                    @Title
                </h2>
                <div class="d-flex">
                    @ButtonContent
                    @if (ShowMoreButton)
                    {
                        <MButton Small="Small" Rounded Color="@(string.IsNullOrWhiteSpace(ButtonColor)?"primary":ButtonColor)" OnClick="OnClickMore" Href="@Href" Target="@Target">
                             <MIcon Left>@IconType.SeeDetails.ToIconString()</MIcon>
                         查看详情
                     </MButton>
                    }
                    @if (Collapable)
                    {
                        <CnGalWebSite.Components.Buttons.MasaButton Color="@(string.IsNullOrWhiteSpace(ButtonColor)?"primary":ButtonColor)" Fab XSmall Icon="@(IsCollapsed?IconType.Collapsed.ToIconString():IconType.UnCollapsed.ToIconString())" Tooltip="@(IsCollapsed?"展开":"折叠")" OnClick="@(() => OnCollapseChanged(!IsCollapsed))" />
                    }
                </div>
            </div>
            @if (Outline == false)
            {
                <div class="@((IsCollapsed ? "d-none " : "") + " content-card "+(HideContentPadding?"":"pa-3 pt-0"))">
                     @ChildContent
             </div>
            }
        </MDCard>
        @if (Outline)
        {
            <MDCard Outline Class="@((IsCollapsed ? "d-none " : "") + " content-card mt-3")">
                 @ChildContent
         </MDCard>
        }
    </section>

}

@code {
    [Parameter]
    public string Icon { get; set; }
    [Parameter]
    public string TextColor { get; set; }
    [Parameter]
    public string ButtonColor { get; set; }

    [Parameter]
    public string Title { get; set; }
    [Parameter]
    public string Class { get; set; }
    [Parameter]
    public RenderFragment ChildContent { get; set; }
    [Parameter]
    public RenderFragment ButtonContent { get; set; }
    [Parameter]
    public bool Collapable { get; set; }
    [Parameter]
    public bool Outline { get; set; }
    [Parameter]
    public bool OutlineHead { get; set; }
    [Parameter]
    public bool OnlyShowContext { get; set; }
    [Parameter]
    public bool IsCollapsed { get; set; }
    [Parameter]
    public bool ShowMoreButton { get; set; }
    [Parameter]
    public bool HideContentPadding { get; set; }
    [Parameter]
    public bool Small { get; set; }
    [Parameter]
    public string SectionId { get; set; }
    [Parameter]
    public string Href { get; set; }
    [Parameter]
    public string Target { get; set; } = "_self";
    [Parameter]
    public EventCallback<bool> IsCollapsedChanged { get; set; }
    [Parameter]
    public EventCallback OnClickMore { get; set; }

    private async Task OnCollapseChanged(bool state)
    {
        IsCollapsed = state;
        await IsCollapsedChanged.InvokeAsync(state);
        StateHasChanged();
    }
}
